from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from .sers import *

class PinlunView(APIView):
    def get(self,request):
        queryset = Pinlun.objects.all()
        ser = PinlunSer(queryset,many=True)
        return Response(ser.data)

    def post(self,request):
        ser = PinlunSer(data=request.data)
        if ser.is_valid():
            ser.save()
            return Response({
                'code':200,
                'msg':'评论成功'
            })
        else:
            return Response({
                'code':400,
                'msg':'评论失败'
            })